﻿using System;
using System.ComponentModel;
using System.Data;
using System.Runtime.CompilerServices;

namespace FixtureManageSystem.Models
{
    public class Borrow : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;


        private int _id;
        public int Id { 
            get { return _id; }
            set { if(value != _id)
                {
                    _id = value;
                    OnPropertyChanged();
                } 
            }
        }
        ///借用人或者归还人的工号
        private string personNo = String.Empty;
        public string PersonNo
        {
            get
            {
                return personNo;
            }
            set
            {
                if (value != this.personNo)
                {
                    personNo = value;
                    OnPropertyChanged();
                }
            }
        }



        /// <summary>
        /// 条形码
        /// </summary>
        /// <param name="barCode"></param>

        private string barCode = String.Empty;
        public string BarCode
        {
            get
            {
                return barCode;
            }
            set
            {
                if (value != this.barCode)
                {
                    barCode = value;
                    OnPropertyChanged();
                }
            }
        }


        /// <summary>
        /// 借用、归还数量
        /// </summary>
        /// <param name="tel"></param>

        private int num = 1;
        public int Num
        {
            get
            {
                return num;
            }
            set
            {
                if (value != this.num)
                {
                    num = value;
                    OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// 借用、归还时间
        /// </summary>
        /// <param name="BorrowTime"></param>

        private DateTime updateTime =  DateTime.Now.Date;
        public DateTime UpdateTime
        {
            get { return updateTime; }
            set {if (value != updateTime)
                {
                    updateTime = value; OnPropertyChanged();
                }
               }
        }

        /// <summary>
        /// 状态，可以是借用、可以是归还
        /// </summary>
        private string _status = "借用";
        public string Status
        {
            get { return _status; }
            set
            {
                if(value != _status)
                {
                    _status = value;
                    OnPropertyChanged();
                }
            }
        }


        /// <summary>
        /// 备注
        /// </summary>
        private string _comment;
        public string Comment
        {
            get { return _comment; }
            set
            {
                if(value != _comment)
                {
                    _comment = value;
                    OnPropertyChanged();
                }
            }
        }

        /// <summary>
        /// 物料名称
        /// </summary>
        private string _name;
        public string Name
        {
            get { return _name; }
            set
            {
                if (value != _name)
                {
                    _name = value;
                    OnPropertyChanged();
                }
            }
        }


        // 物品型号
        private string _materialType;
        public string MaterialType
        {
            get { return _materialType; }
            set
            {
                if (value != _materialType)
                {
                    _materialType = value;
                    OnPropertyChanged();
                }
            }
        }

        // 领用人姓名
        private string _personName;
        public string PersonName
        {
            get { return _personName; }
            set
            {
                if(value != _personName)
                {
                    _personName = value;
                    OnPropertyChanged();
                }
            }
        }

        // 存放位置
        private string _position;
        public string Position
        {
            get { return _position; }
            set
            {
                if(value != _position)
                {
                    _position = value;
                    OnPropertyChanged();
                }
            }
        }


        public override bool Equals(object obj)
        {
            if (obj == null || !(obj is Borrow))
                return false;
            Borrow other = (Borrow)obj;
            return Id == other.Id && Name == other.Name && PersonNo == other.PersonNo && Position == other.Position
                 && PersonName == other.PersonName && MaterialType == other.MaterialType && Comment == other.Comment
                 && Status == other.Status && UpdateTime == other.UpdateTime;
        }

        public static bool operator ==(Borrow s1, Borrow s2)
        {
            if (object.ReferenceEquals(s1, s2))
                return true;

            if (s1 is null || s2 is null)
                return false;

            return s1.Equals(s2);
        }

        public static bool operator !=(Borrow s1, Borrow s2)
        {
            return !(s1 == s2);
        }

        private void OnPropertyChanged([CallerMemberName] String propertyName = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
